package cc.sjfx.sharedoc.activity.examinfo;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import cn.mandroid.frame.toast.MLog;
import cc.sjfx.sharedoc.bean.ExamInfo;

public class ExamInfoDeal {
	private List<ExamInfo> list = new ArrayList<ExamInfo>();
	JSONArray jsonArray;
	private Map<String, Map<String, EInfo>> map = new HashMap<String, Map<String, EInfo>>();
	private String[] groupData = new String[12];

	public ExamInfoDeal(String json) throws JSONException {
		super();
		this.jsonArray = new JSONArray(json);
	}

	public ExamInfoDeal(JSONArray jsonArray) {
		super();
		this.jsonArray = jsonArray;
	}
	public void getExamInfos() throws JSONException {
		Map<String, EInfo> m;
		for (int i = 1; i <= 12; i++) {
			m = new HashMap<String, EInfo>();
			JSONObject jsonObject = jsonArray.getJSONObject(i - 1);
			groupData[i - 1] = jsonObject.getString("month");
			JSONArray jsonArray = new JSONArray(jsonObject.getString("data"));
			for (int j = 0; j < jsonArray.length(); j++) {
				EInfo info=new EInfo();
				jsonObject = jsonArray.getJSONObject(j);
				info.setDate(jsonObject.getString("date"));
				info.setExamName(jsonObject.getString("examName"));
				info.setTime(jsonObject
						.getLong("time"));
				info.setEid(jsonObject.getInt("eid"));
				m.put(j + "", info);
			}
			map.put(i - 1 + "", m);
			ExamInfo.map = map;
			ExamInfo.groupData = groupData;
			ExamInfo.isNull = false;
		}
	}
	public Map<String, Map<String,EInfo>> setTopMonthMap() {
		Map<String, Map<String, EInfo>> m = new HashMap<String, Map<String, EInfo>>();
		SimpleDateFormat formatter = new SimpleDateFormat("MM");
		ExamInfo.gd = new String[12];
		long t=System.currentTimeMillis();
		Date date = new Date(t);
		int month = Integer.parseInt(formatter.format(date));
		int j = 0;
		MLog.i("si:"+ExamInfo.map.size());;
		for (int i = month - 1; i < 12; i++) {
			
			m.put(j + "", ExamInfo.map.get(i + ""));
			ExamInfo.gd[j] = ExamInfo.groupData[i];
			j++;
		}
		for (int i = 0; i < month - 1; i++) {
			m.put(j + "", ExamInfo.map.get(i + ""));
			ExamInfo.gd[j] = ExamInfo.groupData[i];
			j++;
		}
		ExamInfo.month=month;
		return m;
	}
}
